Building a Google Search Application with Macromedia Flash MX Professional
Table of Contents
Authoring Animations
You may have been intimidated at the prospect of authoring animations in Flash because the Timeline and drawing elements required a designer's skills. Besides getting such built-in Timeline effects as drop shadows in Flash MX Professional, you can animate elements in Flash forms as easily as you can animate objects in PowerPoint. You can also author your own motion graphics using movie clips and the standard Timeline. If not, the Timeline stays neatly out of the way.
Here's how you add a simple animated element to the application. For these purposes, add a "loading" element that lets the user know the search is executing:
- Select the frmLoading form screen.
- In the bottom right corner, add a graphical or text element that indicates "loading progress" to the user (see Figure 4). I added a barber pole–style progress bar that I made in a movie clip. You could just add a text tool element (that says "Loading...") and choose Modify > Timeline Effects to create an animation without any authoring at all.
- Hide frmLoading by selecting it and changing the visible property in the Property inspector to false. This prevents the loading widget from appearing by default. Later you'll make this screen visible with ActionScript while the search is executing.
Figure 4. The loading element on the frmLoading form. You can choose any visual element you wish.
Connecting to Data Sources with Components
Flash MX Professional sports a new component architecture, both for UI components and the new data components. In Flash, components aren't compiled code libraries like DLLs. Rather, they are equivalent to controls in VB or Delphi. Flash Professional adds XMLConnector and WebServiceConnector components to automate the interfaces with these two common data sources.
New component bindings allow you to define inputs and outputs for data components. Using the visual design panels built into the IDE, you wire XMLConnector or WebServiceConnector parameters directly to UI components in your forms. Flash features a Parameter tab on the Component inspector that works just like the property pages in VB.
Here's how you use these techniques to connect your application to the Google search service:
- Drag a WebServiceConnector component from the Components panel to the frmSearch form screen. It doesn't matter where you put it; the component won't be visible in the published application. Give the component an instance name of GoogleSearch.
- Select the GoogleSearch component and open the Component inspector. This is where you establish the web service settings. Select the Parameters tab and set the WSDLURL parameter to Google's WSDL URI (as of this writing, it's http://api.google.com/GoogleSearch.wsdl). Flash automatically queries the service and retrieves its available operations. From the operations pop-up menu, select doGoogleSearch (see Figure 5).
- Select the Bindings tab in the Component inspector. This panel allows you to bind the web service inputs and outputs directly to a UI component in the application. Click the + icon to choose which parameters to bind. Input parameters are indicated by a right arrow and output parameters by a left arrow (see Figure 6). The Google interface requires all these input parameters, so add those one by one to the bindings list. Because you're also binding one output parameter, results.searchTime, add it to the list.
- For each binding in the list, you need to set a UI component, a variable reference, or a literal value to pass to or from the web service. First select params.q from the binding list—the search query string to pass to the Google service. To bind it to the TextInput component on the frmSearch form, click the "find" icon in the Bound To row. Flash opens the Bound To dialog box, which displays a hierarchical list of components in your application. Find the txtQuery component instance, select it, and click OK (shown in Figure 7).
- Fill in the rest of the input parameters for the Google service. The other parameters can take literal inputs. To define a literal input, follow the same procedure as in Step 4, except in the Bound To dialog check Use Constant Value and enter the literal into the corresponding text box. Listing 1 shows what values to use for each input parameter.
-
Repeat Step 4 for the results.searchTime output parameter, binding it to the lblSearchTime component instance on frmSearch. The component system allows you to format the input or output before binding. Since the searchTime parameter is just a floating-point number, format this value to make it more intelligible to users. From the Formatter pop-up menu, select Compose String. Then click Formatter Options, and enter the following string into the dialog box:
Search time: <.> seconds
The parameter value will be substituted for the <.> placeholder when the component binds.

Figure 5. Selecting the web service operation in the Component inspector

Figure 6. Selecting web service parameters in the Component inspector

Figure 7. Binding the web service input parameter to a UI component in the Component inspector
params.key [Your Google Web API License Key] params.start 0 params.maxResults 10 params.filter true params.restrict [empty string] params.safeSearch true params.lr [empty string] params.ie [empty string] params.oe [empty string]
Listing 1. doGoogleSearch web service parameter settings
Note: By default, Macromedia Flash Player security restrictions prohibit Flash movies from accessing web services that reside outside the exact domain of the SWF attempting to access those web services. This restriction does not apply to SWFs that are run locally off your hard drive, only those that originate from a web server. A SWF can access a cross-domain web service if the server hosting that server contains a security policy file. To learn more about Flash Player security restriction and policy files, see "Security Changes in Macromedia Flash Player 7."